home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Complementary Applications 2004 May / SGI IRIX 6.5 Complementary Applications 2004 May.iso / dist / PPRO.idb / usr / include / cups / http.h.z / http.h
Encoding:
C/C++ Source or Header  |  2004-01-20  |  11.3 KB  |  370 lines

  1. /*
  2.  * "$Id: http.h,v 1.47 2003/08/29 21:26:41 mike Exp $"
  3.  *
  4.  *   Hyper-Text Transport Protocol definitions for the Common UNIX Printing
  5.  *   System (CUPS).
  6.  *
  7.  *   Copyright 1997-2003 by Easy Software Products, all rights reserved.
  8.  *
  9.  *   These coded instructions, statements, and computer programs are the
  10.  *   property of Easy Software Products and are protected by Federal
  11.  *   copyright law.  Distribution and use rights are outlined in the file
  12.  *   "LICENSE.txt" which should have been included with this file.  If this
  13.  *   file is missing or damaged please contact Easy Software Products
  14.  *   at:
  15.  *
  16.  *       Attn: CUPS Licensing Information
  17.  *       Easy Software Products
  18.  *       44141 Airport View Drive, Suite 204
  19.  *       Hollywood, Maryland 20636-3111 USA
  20.  *
  21.  *       Voice: (301) 373-9603
  22.  *       EMail: cups-info@cups.org
  23.  *         WWW: http://www.cups.org
  24.  *
  25.  *   This file is subject to the Apple OS-Developed Software exception.
  26.  */
  27.  
  28. #ifndef _CUPS_HTTP_H_
  29. #  define _CUPS_HTTP_H_
  30.  
  31. /*
  32.  * Include necessary headers...
  33.  */
  34.  
  35. #  include <string.h>
  36. #  include <time.h>
  37. #  ifdef WIN32
  38. #    include <winsock.h>
  39. #  else
  40. #    include <unistd.h>
  41. #    include <sys/time.h>
  42. #    include <sys/types.h>
  43. #    include <sys/socket.h>
  44. #    include <netdb.h>
  45. #    include <netinet/in.h>
  46. #    include <arpa/inet.h>
  47. #    include <netinet/in_systm.h>
  48. #    include <netinet/ip.h>
  49. #    if !defined(__APPLE__) || !defined(TCP_NODELAY)
  50. #      include <netinet/tcp.h>
  51. #    endif /* !__APPLE__ || !TCP_NODELAY */
  52. #  endif /* WIN32 */
  53.  
  54. #  include "md5.h"
  55.  
  56.  
  57. /*
  58.  * C++ magic...
  59.  */
  60.  
  61. #  ifdef __cplusplus
  62. extern "C" {
  63. #  endif /* __cplusplus */
  64.  
  65.  
  66. /*
  67.  * Limits...
  68.  */
  69.  
  70. #  define HTTP_MAX_URI        1024    /* Max length of URI string */
  71. #  define HTTP_MAX_HOST        256    /* Max length of hostname string */
  72. #  define HTTP_MAX_BUFFER    2048    /* Max length of data buffer */
  73. #  define HTTP_MAX_VALUE    256    /* Max header field value length */
  74.  
  75.  
  76. /*
  77.  * HTTP state values...
  78.  */
  79.  
  80. typedef enum            /* States are server-oriented */
  81. {
  82.   HTTP_WAITING,            /* Waiting for command */
  83.   HTTP_OPTIONS,            /* OPTIONS command, waiting for blank line */
  84.   HTTP_GET,            /* GET command, waiting for blank line */
  85.   HTTP_GET_SEND,        /* GET command, sending data */
  86.   HTTP_HEAD,            /* HEAD command, waiting for blank line */
  87.   HTTP_POST,            /* POST command, waiting for blank line */
  88.   HTTP_POST_RECV,        /* POST command, receiving data */
  89.   HTTP_POST_SEND,        /* POST command, sending data */
  90.   HTTP_PUT,            /* PUT command, waiting for blank line */
  91.   HTTP_PUT_RECV,        /* PUT command, receiving data */
  92.   HTTP_DELETE,            /* DELETE command, waiting for blank line */
  93.   HTTP_TRACE,            /* TRACE command, waiting for blank line */
  94.   HTTP_CLOSE,            /* CLOSE command, waiting for blank line */
  95.   HTTP_STATUS            /* Command complete, sending status */
  96. } http_state_t;
  97.  
  98.  
  99. /*
  100.  * HTTP version numbers...
  101.  */
  102.  
  103. typedef enum
  104. {
  105.   HTTP_0_9 = 9,            /* HTTP/0.9 */
  106.   HTTP_1_0 = 100,        /* HTTP/1.0 */
  107.   HTTP_1_1 = 101        /* HTTP/1.1 */
  108. } http_version_t;
  109.  
  110.  
  111. /*
  112.  * HTTP keep-alive values...
  113.  */
  114.  
  115. typedef enum
  116. {
  117.   HTTP_KEEPALIVE_OFF = 0,
  118.   HTTP_KEEPALIVE_ON
  119. } http_keepalive_t;
  120.  
  121.  
  122. /*
  123.  * HTTP transfer encoding values...
  124.  */
  125.  
  126. typedef enum
  127. {
  128.   HTTP_ENCODE_LENGTH,        /* Data is sent with Content-Length */
  129.   HTTP_ENCODE_CHUNKED        /* Data is chunked */
  130. } http_encoding_t;
  131.  
  132.  
  133. /*
  134.  * HTTP encryption values...
  135.  */
  136.  
  137. typedef enum
  138. {
  139.   HTTP_ENCRYPT_IF_REQUESTED,    /* Encrypt if requested (TLS upgrade) */
  140.   HTTP_ENCRYPT_NEVER,        /* Never encrypt */
  141.   HTTP_ENCRYPT_REQUIRED,    /* Encryption is required (TLS upgrade) */
  142.   HTTP_ENCRYPT_ALWAYS        /* Always encrypt (SSL) */
  143. } http_encryption_t;
  144.  
  145.  
  146. /*
  147.  * HTTP authentication types...
  148.  */
  149.  
  150. typedef enum
  151. {
  152.   HTTP_AUTH_NONE,        /* No authentication in use */
  153.   HTTP_AUTH_BASIC,        /* Basic authentication in use */
  154.   HTTP_AUTH_MD5,        /* Digest authentication in use */
  155.   HTTP_AUTH_MD5_SESS,        /* MD5-session authentication in use */
  156.   HTTP_AUTH_MD5_INT,        /* Digest authentication in use for body */
  157.   HTTP_AUTH_MD5_SESS_INT    /* MD5-session authentication in use for body */
  158. } http_auth_t;
  159.  
  160.  
  161. /*
  162.  * HTTP status codes...
  163.  */
  164.  
  165. typedef enum
  166. {
  167.   HTTP_ERROR = -1,        /* An error response from httpXxxx() */
  168.  
  169.   HTTP_CONTINUE = 100,        /* Everything OK, keep going... */
  170.   HTTP_SWITCHING_PROTOCOLS,    /* HTTP upgrade to TLS/SSL */
  171.  
  172.   HTTP_OK = 200,        /* OPTIONS/GET/HEAD/POST/TRACE command was successful */
  173.   HTTP_CREATED,            /* PUT command was successful */
  174.   HTTP_ACCEPTED,        /* DELETE command was successful */
  175.   HTTP_NOT_AUTHORITATIVE,    /* Information isn't authoritative */
  176.   HTTP_NO_CONTENT,        /* Successful command, no new data */
  177.   HTTP_RESET_CONTENT,        /* Content was reset/recreated */
  178.   HTTP_PARTIAL_CONTENT,        /* Only a partial file was recieved/sent */
  179.  
  180.   HTTP_MULTIPLE_CHOICES = 300,    /* Multiple files match request */
  181.   HTTP_MOVED_PERMANENTLY,    /* Document has moved permanently */
  182.   HTTP_MOVED_TEMPORARILY,    /* Document has moved temporarily */
  183.   HTTP_SEE_OTHER,        /* See this other link... */
  184.   HTTP_NOT_MODIFIED,        /* File not modified */
  185.   HTTP_USE_PROXY,        /* Must use a proxy to access this URI */
  186.  
  187.   HTTP_BAD_REQUEST = 400,    /* Bad request */
  188.   HTTP_UNAUTHORIZED,        /* Unauthorized to access host */
  189.   HTTP_PAYMENT_REQUIRED,    /* Payment required */
  190.   HTTP_FORBIDDEN,        /* Forbidden to access this URI */
  191.   HTTP_NOT_FOUND,        /* URI was not found */
  192.   HTTP_METHOD_NOT_ALLOWED,    /* Method is not allowed */
  193.   HTTP_NOT_ACCEPTABLE,        /* Not Acceptable */
  194.   HTTP_PROXY_AUTHENTICATION,    /* Proxy Authentication is Required */
  195.   HTTP_REQUEST_TIMEOUT,        /* Request timed out */
  196.   HTTP_CONFLICT,        /* Request is self-conflicting */
  197.   HTTP_GONE,            /* Server has gone away */
  198.   HTTP_LENGTH_REQUIRED,        /* A content length or encoding is required */
  199.   HTTP_PRECONDITION,        /* Precondition failed */
  200.   HTTP_REQUEST_TOO_LARGE,    /* Request entity too large */
  201.   HTTP_URI_TOO_LONG,        /* URI too long */
  202.   HTTP_UNSUPPORTED_MEDIATYPE,    /* The requested media type is unsupported */
  203.   HTTP_UPGRADE_REQUIRED = 426,    /* Upgrade to SSL/TLS required */
  204.  
  205.   HTTP_SERVER_ERROR = 500,    /* Internal server error */
  206.   HTTP_NOT_IMPLEMENTED,        /* Feature not implemented */
  207.   HTTP_BAD_GATEWAY,        /* Bad gateway */
  208.   HTTP_SERVICE_UNAVAILABLE,    /* Service is unavailable */
  209.   HTTP_GATEWAY_TIMEOUT,        /* Gateway connection timed out */
  210.   HTTP_NOT_SUPPORTED        /* HTTP version not supported */
  211. } http_status_t;
  212.  
  213.  
  214. /*
  215.  * HTTP field names...
  216.  */
  217.  
  218. typedef enum
  219. {
  220.   HTTP_FIELD_UNKNOWN = -1,
  221.   HTTP_FIELD_ACCEPT_LANGUAGE,
  222.   HTTP_FIELD_ACCEPT_RANGES,
  223.   HTTP_FIELD_AUTHORIZATION,
  224.   HTTP_FIELD_CONNECTION,
  225.   HTTP_FIELD_CONTENT_ENCODING,
  226.   HTTP_FIELD_CONTENT_LANGUAGE,
  227.   HTTP_FIELD_CONTENT_LENGTH,
  228.   HTTP_FIELD_CONTENT_LOCATION,
  229.   HTTP_FIELD_CONTENT_MD5,
  230.   HTTP_FIELD_CONTENT_RANGE,
  231.   HTTP_FIELD_CONTENT_TYPE,
  232.   HTTP_FIELD_CONTENT_VERSION,
  233.   HTTP_FIELD_DATE,
  234.   HTTP_FIELD_HOST,
  235.   HTTP_FIELD_IF_MODIFIED_SINCE,
  236.   HTTP_FIELD_IF_UNMODIFIED_SINCE,
  237.   HTTP_FIELD_KEEP_ALIVE,
  238.   HTTP_FIELD_LAST_MODIFIED,
  239.   HTTP_FIELD_LINK,
  240.   HTTP_FIELD_LOCATION,
  241.   HTTP_FIELD_RANGE,
  242.   HTTP_FIELD_REFERER,
  243.   HTTP_FIELD_RETRY_AFTER,
  244.   HTTP_FIELD_TRANSFER_ENCODING,
  245.   HTTP_FIELD_UPGRADE,
  246.   HTTP_FIELD_USER_AGENT,
  247.   HTTP_FIELD_WWW_AUTHENTICATE,
  248.   HTTP_FIELD_MAX
  249. } http_field_t;
  250.   
  251.  
  252. /*
  253.  * HTTP connection structure...
  254.  */
  255.  
  256. typedef struct
  257. {
  258.   int            fd;        /* File descriptor for this socket */
  259.   int            blocking;    /* To block or not to block */
  260.   int            error;        /* Last error on read */
  261.   time_t        activity;    /* Time since last read/write */
  262.   http_state_t        state;        /* State of client */
  263.   http_status_t        status;        /* Status of last request */
  264.   http_version_t    version;    /* Protocol version */
  265.   http_keepalive_t    keep_alive;    /* Keep-alive supported? */
  266.   struct sockaddr_in    hostaddr;    /* Address of connected host */
  267.   char            hostname[HTTP_MAX_HOST],
  268.                       /* Name of connected host */
  269.             fields[HTTP_FIELD_MAX][HTTP_MAX_VALUE];
  270.                     /* Field values */
  271.   char            *data;        /* Pointer to data buffer */
  272.   http_encoding_t    data_encoding;    /* Chunked or not */
  273.   int            data_remaining;    /* Number of bytes left */
  274.   int            used;        /* Number of bytes used in buffer */
  275.   char            buffer[HTTP_MAX_BUFFER];
  276.                     /* Buffer for messages */
  277.   int            auth_type;    /* Authentication in use */
  278.   md5_state_t        md5_state;    /* MD5 state */
  279.   char            nonce[HTTP_MAX_VALUE];
  280.                     /* Nonce value */
  281.   int            nonce_count;    /* Nonce count */
  282.   void            *tls;        /* TLS state information */
  283.   http_encryption_t    encryption;    /* Encryption requirements */
  284.   /**** New in CUPS 1.1.19 ****/
  285.   fd_set        *input_set;    /* select() set for httpWait() */
  286.   http_status_t        expect;        /* Expect: header */
  287.   char            *cookie;    /* Cookie value(s) */
  288.   /**** New in CUPS 1.1.20 ****/
  289.   char            authstring[HTTP_MAX_VALUE],
  290.                     /* Current Authentication value */
  291.             userpass[HTTP_MAX_VALUE];
  292.                     /* Username:password string */
  293.   int            digest_tries;    /* Number of tries for digest auth */
  294. } http_t;
  295.  
  296.  
  297. /*
  298.  * Prototypes...
  299.  */
  300.  
  301. #  define        httpBlocking(http,b)    (http)->blocking = (b)
  302. extern int        httpCheck(http_t *http);
  303. #  define        httpClearFields(http)    memset((http)->fields, 0, sizeof((http)->fields)),\
  304.                         httpSetField((http), HTTP_FIELD_HOST, (http)->hostname)
  305. extern void        httpClose(http_t *http);
  306. extern http_t        *httpConnect(const char *host, int port);
  307. extern http_t        *httpConnectEncrypt(const char *host, int port,
  308.                                 http_encryption_t encrypt);
  309. extern int        httpDelete(http_t *http, const char *uri);
  310. extern int        httpEncryption(http_t *http, http_encryption_t e);
  311. #  define        httpError(http) ((http)->error)
  312. extern void        httpFlush(http_t *http);
  313. extern int        httpGet(http_t *http, const char *uri);
  314. extern char        *httpGets(char *line, int length, http_t *http);
  315. extern const char    *httpGetDateString(time_t t);
  316. extern time_t        httpGetDateTime(const char *s);
  317. #  define        httpGetField(http,field)    (http)->fields[field]
  318. extern struct hostent    *httpGetHostByName(const char *name);
  319. extern char        *httpGetSubField(http_t *http, http_field_t field,
  320.                              const char *name, char *value);
  321. extern int        httpHead(http_t *http, const char *uri);
  322. extern void        httpInitialize(void);
  323. extern int        httpOptions(http_t *http, const char *uri);
  324. extern int        httpPost(http_t *http, const char *uri);
  325. extern int        httpPrintf(http_t *http, const char *format, ...)
  326. #  ifdef __GNUC__
  327. __attribute__ ((__format__ (__printf__, 2, 3)))
  328. #  endif /* __GNUC__ */
  329. ;
  330. extern int        httpPut(http_t *http, const char *uri);
  331. extern int        httpRead(http_t *http, char *buffer, int length);
  332. extern int        httpReconnect(http_t *http);
  333. extern void        httpSeparate(const char *uri, char *method,
  334.                          char *username, char *host, int *port,
  335.                      char *resource);
  336. extern void        httpSetField(http_t *http, http_field_t field,
  337.                          const char *value);
  338. extern const char    *httpStatus(http_status_t status);
  339. extern int        httpTrace(http_t *http, const char *uri);
  340. extern http_status_t    httpUpdate(http_t *http);
  341. extern int        httpWrite(http_t *http, const char *buffer, int length);
  342. extern char        *httpEncode64(char *out, const char *in);
  343. extern char        *httpDecode64(char *out, const char *in);
  344. extern int        httpGetLength(http_t *http);
  345. extern char        *httpMD5(const char *, const char *, const char *,
  346.                      char [33]);
  347. extern char        *httpMD5Final(const char *, const char *, const char *,
  348.                           char [33]);
  349. extern char        *httpMD5String(const md5_byte_t *, char [33]);
  350.  
  351. /**** New in CUPS 1.1.19 ****/
  352. extern void        httpClearCookie(http_t *http);
  353. #define httpGetCookie(http) ((http)->cookie)
  354. extern void        httpSetCookie(http_t *http, const char *cookie);
  355. extern int        httpWait(http_t *http, int msec);
  356.  
  357.  
  358. /*
  359.  * C++ magic...
  360.  */
  361.  
  362. #  ifdef __cplusplus
  363. }
  364. #  endif /* __cplusplus */
  365. #endif /* !_CUPS_HTTP_H_ */
  366.  
  367. /*
  368.  * End of "$Id: http.h,v 1.47 2003/08/29 21:26:41 mike Exp $".
  369.  */
  370.